<?php
/**
 * Created by PhpStorm.
 * User: hezhizheng
 */

namespace App\Services\Utils;

use Jenssegers\Agent\Agent as JenssegersAgent;

class Agent
{
    private $agent;

    public function __construct()
    {
        $this->agent = (new JenssegersAgent);
    }

    /**
     * @link https://laravel-china.org/topics/782/extended-recommendation-laravel-user-agent-easily-identify-client-information
     * (new App\Services\Utils\Agent)->agentInfo()
     * @return array
     */
    public function agentInfo()
    {
        // 语言 ['nl-nl', 'nl', 'en-us', 'en']
        $languages = $this->agent->languages();

        // 是否是机器人
        $isRobot = $this->agent->isRobot();

        // 获取设备信息 (iPhone, Nexus, AsusTablet, ...)
        $device = $this->agent->device();

        // 系统信息  (Ubuntu, Windows, OS X, ...)
        $platform = $this->agent->platform();
        // 获取系统版本
        $platform_version = $this->agent->version($platform);

        // 浏览器信息  (Chrome, IE, Safari, Firefox, ...)
        $browser = $this->agent->browser();
        // 获取浏览器版本
        $browser_version = $this->agent->version($browser);

        return compact(
            'languages', 'isRobot', 'device',
            'platform', 'platform_version', 'browser', 'browser_version');
    }

}